
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Day04-2 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Day05-2.html" />
    
    
    <link rel="prev" href="Day04-1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="Day01.html">
            
                <a href="Day01.html">
            
                    
                    Day01
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Day02.html">
            
                <a href="Day02.html">
            
                    
                    Day02
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Day03.html">
            
                <a href="Day03.html">
            
                    
                    Day03
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Day04-1.html">
            
                <a href="Day04-1.html">
            
                    
                    Day04-1
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="Day04-2.html">
            
                <a href="Day04-2.html">
            
                    
                    Day04-2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Day05-2.html">
            
                <a href="Day05-2.html">
            
                    
                    Day05-1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Day05-1.html">
            
                <a href="Day05-1.html">
            
                    
                    Day05-2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Day06.html">
            
                <a href="Day06.html">
            
                    
                    Day06
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Day04-2</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="day04-shell&#x7F16;&#x7A0B;&#x57FA;&#x7840;&#x8BFE;&#x4E60;&#x9898;">Day04-shell&#x7F16;&#x7A0B;&#x57FA;&#x7840;&#x8BFE;&#x4E60;&#x9898;</h1>
<p>Author&#xFF1A;<code>10-MF&#x8D3E;-Py201704024</code>
Date&#xFF1A;<code>6&#x6708;13&#x65E5;</code></p>
<h3 id="1-&#x83B7;&#x53D6;&#x672C;&#x673A;&#x7684;ip-&#x901A;&#x8FC7;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;">1) &#x83B7;&#x53D6;&#x672C;&#x673A;&#x7684;IP &#x901A;&#x8FC7;&#x51E0;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;</h3>
<pre><code class="lang-shell">ifconfig eth0 | grep &quot;Bcast&quot; | cut -d &quot;:&quot; -f2 | cut -d &quot; &quot; -f1
192.168.0.104

ifconfig eth0 | grep &quot;Bcast&quot; | awk -F&apos;[ :]+&apos; &apos;{print $4}&apos;
192.168.0.104

ifconfig eth0 | grep &quot;Bcast&quot; | cut -d &quot;:&quot; -f2 | awk &apos;{print $1}&apos;
192.168.0.104

ifconfig eth0 | awk -F &apos;[ :]+&apos; &apos;/Bcast/{print $4}&apos;
192.168.0.104

ifconfig eth0 | awk &apos;/Bcast/{print $2}&apos; | cut -c 6-        # &#x4ECE;&#x7B2C;&#x516D;&#x4E2A;&#x5B57;&#x7B26;&#x5F00;&#x59CB;&#x622A;&#x53D6;
192.168.0.104
</code></pre>
<h3 id="2-&#x83B7;&#x53D6;&#x673A;&#x5668;&#x4E0A;&#x76D1;&#x542C;&#x7684;&#x6240;&#x6709;&#x7AEF;&#x53E3;&#x5C1D;&#x8BD5;&#x7528;&#x5176;&#x4ED6;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;">2) &#x83B7;&#x53D6;&#x673A;&#x5668;&#x4E0A;&#x76D1;&#x542C;&#x7684;&#x6240;&#x6709;&#x7AEF;&#x53E3;&#x5C1D;&#x8BD5;&#x7528;&#x5176;&#x4ED6;&#x7684;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;</h3>
<pre><code class="lang-shell"># &#x67E5;&#x8BE2;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x6B63;&#x5728;&#x76D1;&#x542C;&#x7684;&#x7AEF;&#x53E3;&#x53F7;&#x548C;&#x5BF9;&#x5E94;&#x7684;&#x670D;&#x52A1;PID&#x548C;&#x670D;&#x52A1;&#x540D;
netstat -naltup | awk &apos;/LISTEN/{print $4,$7}&apos; | awk -F&quot;:&quot; &apos;{print $NF}&apos; | sort -n | uniq
22 1077/sshd
25 1156/master
80 1986/nginx
# &#x67E5;&#x8BE2;&#x670D;&#x52A1;&#x5668;&#x4E0A;22&#x7AEF;&#x53E3;&#x548C;&#x5916;&#x90E8;&#x8FDE;&#x63A5;&#x7684;&#x4E2A;&#x6570;
netstat -naltup | grep -v &quot;LISTEN&quot; | grep &quot;:22&quot; | wc -l
4
# &#x67E5;&#x8BE2;&#x670D;&#x52A1;&#x5668;&#x4E0A;25&#x7AEF;&#x53E3;&#x548C;&#x5916;&#x90E8;&#x8FDE;&#x63A5;&#x7684;&#x4E2A;&#x6570;
netstat -naltup | grep -v &quot;LISTEN&quot; | grep &quot;:25&quot; | wc -l
0
# &#x67E5;&#x8BE2;&#x670D;&#x52A1;&#x5668;&#x4E0A;80&#x7AEF;&#x53E3;&#x548C;&#x5916;&#x90E8;&#x8FDE;&#x63A5;&#x7684;&#x4E2A;&#x6570;
netstat -naltup | grep -v &quot;LISTEN&quot; | grep &quot;:80&quot; | wc -l
5
</code></pre>
<h3 id="3-&#x5199;&#x4E00;&#x4E2A;&#x7A0B;&#x5E8F;&#x7684;&#x542F;&#x52A8;&#x811A;&#x672C;&#x6839;&#x636E;&#x4F8B;&#x5B50;&#x6765;&#x5199;">3) &#x5199;&#x4E00;&#x4E2A;&#x7A0B;&#x5E8F;&#x7684;&#x542F;&#x52A8;&#x811A;&#x672C;&#x6839;&#x636E;&#x4F8B;&#x5B50;&#x6765;&#x5199;</h3>
<pre><code class="lang-shell">#!/bin/bash
#
# nginxd        Start up the NGINX server daemon
#
# chkconfig: 2345 55 25
# description: NGINX is an HTTP and reverse proxy server, \
#                a mail proxy server, and a generic TCP/UDP proxy server
#
# processname: nginxd
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx.pid
# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

# source function library
. /etc/rc.d/init.d/functions

prog=nginx
pro_name=&quot;/usr/sbin/nginx&quot;
CONF_FILE=&quot;/etc/nginx/nginx.conf&quot;
lockfile=&quot;/var/lock/subsys/nginx&quot;

start() {
    [ -x $pro_name ] || exit 5
    [ -f $CONF_FILE ] || exit 6
    echo -n $&quot;Starting $prog: &quot;
    daemon $pro_name -c $CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] &amp;&amp; touch $lockfile
    return $retval
}

stop() {
    echo -n $&quot;Stopping $prog: &quot;
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] &amp;&amp; rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 3
    start
}

reload() {
    configtest || return $?
    echo -n $&quot;Reloading $prog: &quot;
    killproc $pro_name -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $pro_name -t -c $CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status &gt;/dev/null 2&gt;&amp;1
}

case &quot;$1&quot; in
    start)
        rh_status_q &amp;&amp; exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $&quot;Usage: $0 {start|stop|status|restart|reload|configtest}&quot;
        exit 2
esac
</code></pre>
<p>&#x628A;&#x542F;&#x52A8;&#x7A0B;&#x5E8F;&#x547D;&#x540D;&#x4E3A;<code>nginxd</code>&#xFF0C;&#x5E76;&#x653E;&#x5230; <code>/etc/init.d/</code> &#x4E0B;&#xFF0C;&#x6D4B;&#x8BD5;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-shell">[root@localhost ~]# service nginxd status
nginx (pid  1403) is running...
[root@localhost ~]# service nginxd stop
Stopping nginx:                                            [  OK  ]
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# service nginxd start
Starting nginx:                                            [  OK  ]
[root@localhost ~]# service nginxd reload
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reloading nginx:                                           [  OK  ]
[root@localhost ~]# service nginxd restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]# service nginxd configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
</code></pre>
<h3 id="4-&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#x9762;&#x521D;&#x59CB;&#x5316;&#x811A;&#x672C;">4) &#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#x9762;&#x521D;&#x59CB;&#x5316;&#x811A;&#x672C;</h3>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Day04-1.html" class="navigation navigation-prev " aria-label="Previous page: Day04-1">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Day05-2.html" class="navigation navigation-next " aria-label="Next page: Day05-1">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Day04-2","level":"1.6","depth":1,"next":{"title":"Day05-1","level":"1.7","depth":1,"path":"Day05-2.md","ref":"Day05-2.md","articles":[]},"previous":{"title":"Day04-1","level":"1.5","depth":1,"path":"Day04-1.md","ref":"Day04-1.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"Day04-2.md","mtime":"2017-06-14T17:50:55.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-07-01T15:45:14.694Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

